<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <link rel="stylesheet" href="../css/basic.css">
  <style  type="text/css">
  .show{
    	
    }
    .show img{
        width: 300px;
        height: 300px;
        float: left;
        margin: 25px 10px;
    }
    
    .show h5{
    	color:#FF5722;
    	font-size:30px;
    }
    .show p{
    	font-size:20px;
    }
  </style>
</head>
<body>
<script>
!function(){function n(n,e,t){return n.getAttribute(e)||t}function e(n){return document.getElementsByTagName(n)}function t(){var t=e("script"),o=t.length,i=t[o-1];return{l:o,z:n(i,"zIndex",-1),o:n(i,"opacity",.9),c:n(i,"color","0,0,0"),n:n(i,"count",99)}}function o(){a=m.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,c=m.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}function i(){r.clearRect(0,0,a,c);var n,e,t,o,m,l;s.forEach(function(i,x){for(i.x+=i.xa,i.y+=i.ya,i.xa*=i.x>a||i.x<0?-1:1,i.ya*=i.y>c||i.y<0?-1:1,r.fillRect(i.x-.5,i.y-.5,1,1),e=x+1;e<u.length;e++)n=u[e],null!==n.x&&null!==n.y&&(o=i.x-n.x,m=i.y-n.y,l=o*o+m*m,l<n.max&&(n===y&&l>=n.max/2&&(i.x-=.03*o,i.y-=.03*m),t=(n.max-l)/n.max,r.beginPath(),r.lineWidth=t/2,r.strokeStyle="rgba("+d.c+","+(t+.2)+")",r.moveTo(i.x,i.y),r.lineTo(n.x,n.y),r.stroke()))}),x(i)}var a,c,u,m=document.createElement("canvas"),d=t(),l="c_n"+d.l,r=m.getContext("2d"),x=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n){window.setTimeout(n,1e3/45)},w=Math.random,y={x:null,y:null,max:2e4};m.id=l,m.style.cssText="position:fixed;top:0;left:0;z-index:"+d.z+";opacity:"+d.o,e("body")[0].appendChild(m),o(),window.onresize=o,window.onmousemove=function(n){n=n||window.event,y.x=n.clientX,y.y=n.clientY},window.onmouseout=function(){y.x=null,y.y=null};for(var s=[],f=0;d.n>f;f++){var h=w()*a,g=w()*c,v=2*w()-1,p=2*w()-1;s.push({x:h,y:g,xa:v,ya:p,max:6e3})}u=s.concat([y]),setTimeout(function(){i()},100)}();
</script>
  <div class="layui-container bs-center" >
        <form action="" class="bs-center layui-form" id="seaActivity" lay-filter="seaActivity">
            <div class="layui-col-sm5 layui-form-item">
                <label class="layui-form-label">社团名：</label>
                <div class="layui-input-block">
                <input type="text" name="soc_name" class="layui-input">
                </div>
            </div>
            <div class="layui-col-sm5">
                <label class="layui-form-label">社团ID：</label>
                <div class="layui-input-block">
                <input type="text" name="soc_no" class="layui-input">
                </div>
            </div>
            <div class="layui-col-sm2">
                <a id="searchIpt" class="layui-btn layui-btn-normal">搜索</a>
            </div>
        </form>
        <table class="layui-table" id="partyTable" lay-filter="partyTable"></table>
  </div>
</body>
<div class="layui-tab layui-tab-brief  bs-hidden" id="partyDetail" lay-filter="partyDetail">
  <div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
      <form action="" class="layui-form fm-in" lay-filter="partyCard" id="partyCard">
      	<fieldset class="layui-elem-field">
		  <legend> <label id="soc_name"></label> - <label id="soc_unit"> </label> </legend>
		  <div class="layui-field-box  show">
		    <img src="../img_society/10001.png" id="soc_pic">
		    <h5>介绍</h5>
      		<p id="soc_intro"></p>
		  </div>
		</fieldset>
      </form>
    </div>
  </div>
</div>
<span class="bs-hidden" id="StuNo"></span>
<script type="text/html" id="ipts">
    <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="addPar">加入</a>
</script>    
<script>
 layui.use(['laydate','form','jquery','layer','table'], function(){
  var laydate = layui.laydate;
  var form = layui.form
  var $ = layui.jquery
  var layer = layui.layer
  var table = layui.table;
  //自定义验证规则
  form.verify({
    //为账号定义的验证添加规则
  })
//ajax
	$.ajax({
	  	type:"POST",
	  	url:"/user/getStuUser", //通过session获取当前Society
	  	dataType:"json",
	  	error:function(){
	  		console.log("error!");
	  	},
	  	success:function(data){
	  		console.log(data);
	  		$('#StuNo').html(data.stu_no);  
	  		searchAll();
	  	}
	});
function searchAll(){  //查询当前学生的社团
	$.ajax({
		type:"GET",
		url:"/student/serchSociety",
		data:{"stu_no":$('#StuNo').text()},//写完登录后更改
		dataType:"json",
		error:function(){
			alert("error!");
		},
		success:function(data){
			console.log(data);
			//注入动态表格
			showTable(data);	
		}
	})  	  
}//searchAll();
//搜索
$('#searchIpt').click(function (event){
      console.log($('#search').serialize())
      $.get('/student/serchSocietyByFuzzy', $('#seaActivity').serialize(), function (res) {
        console.log(res)
        console.log(1)
        showTable(res)
      }, "json")
      event.preventDefault()
 })//ajax click
//表格
function showTable(data){
	  table.render({
		    elem: '#partyTable',
		    page: true,//开启分页
		    cols: [[ //标题栏
		     	{
		          field: 'soc_no',
		          title: '社团号',
		          width: "8%",
		          align:"center"
		         },{
		          field: 'soc_name',
		          title: '社团名称',
		          width: "18%",
		          align:"center"
		         },{
		          field: 'soc_type',
		          title: '社团类别',
		          width: "8%",
		          align:"center"
		         },{
		           field: 'soc_unit',
		           title: '挂靠单位',
		           width: "12%",
		           align:"center"
		         },{
		             field: 'soc_man',
		             title: '负责人',
		             width: "8%",
		             align:"center"
		         },{
		             field: 'soc_tele',
		             title: '联系电话',
		             width: "11%",
		             align:"center"
		         },{
		             field: 'soc_count',
		             title: '当前人数',
		             width: "8%",
		             align:"center"
		         },{
		             field: 'soc_intro',
		             title: '社团介绍',
		             width: "15%",
		             align:"center"
		         },{
		             field: 'btn',
		             title: '操作',
		             width: "11.9%",
		             align:"center",
		             toolbar:"#ipts"
		         }
		        ]],
		    data: data,
		});
	  }//showTable
    table.on('tool(partyTable)', function (obj) {
        var event = obj.event;
        var that = $(this);
        if(event ==='detail'){
        	$("#soc_pic").attr("src",obj.data.soc_pic);
            $("#soc_name").html(obj.data.soc_name);
            $("#soc_unit").html(obj.data.soc_unit);
            $("#soc_name").html(obj.data.soc_name);
            $("#soc_intro").text(obj.data.soc_intro);
	       	layer.open({
	       		title:"社团详情",
	       		type: 1,
	       		closeBtn: 0,
	       		content: $('#partyDetail'),
	       		area:['100%','100%'],
	       		btn:['返回'],
                btnAlign:'c',
                yes:function(index, layero){
               	 layer.close(index);
                 return false;
               },
	        });
        }else if(event === 'addPar') {
	        layer.open({
	          type:1,
	          closeBtn: 0,
	          title:"提示信息",
	          content:"<span style='font-size:20px; margin-left:40px'>"+"真的加入么？"+"</span>",
	          area:['200px','150px'],
	          btn:['确定','取消'],
	          btnAlign:'c',
	          yes:function(index, layero){
	        	  $.ajax({
	             		type:"POST",
	             		data:{
	             			"stu_no":$('#StuNo').text(),
	             			"soc_no":obj.data.soc_no
	             		},
	             		url:"/student/joinSociety",
	             		dataType:"json",
	             		error:function(){
	             			alert("已加入过，请勿多次加入！");
	             		},
	             		success:function(data){
	             			console.log(data);
	             			if(data == true){
	             				layer.msg('加入成功!',{
	             					time:1000
	             				},function(){
	             					layer.closeAll();
	             				});
	             				searchAll();
	             				return false;
	             			}else if(data == false){
	             				layer.msg('加入失败!',{
	             					time:1000
	             				},function(){
	             					layer.closeAll();
	             				});
	             				searchAll();
	             				return false;
	             			}
	             		}	
	              	})
	          },
	          btn2:function(index, layero){
	              layer.close(index);
	              return false;
	          }
	        });//open
    }//else if
    });
});
</script>
</html>

